package com.gongj.stream.demo1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Stream;

/*
 * 流的常用创建方法
 */
public class demo1 {

    public static void main(String[] args) {
        // 使用Collection系列集合提供的 stream() 和 parallelStream() 方法
        ArrayList<String> list = new ArrayList<>();
        //返回一个顺序流
        Stream<String> stream = list.stream();
        //把顺序流转换成并行流
        Stream<String> parallel = list.stream().parallel();
        //返回一个并行流
        Stream<String> stringStream = list.parallelStream();

        String[] strs = new String[10];
        Stream<String> stream2 = Arrays.stream(strs);


        Stream<String> aa = Stream.of("aa", "bbb", "c");

        //无限流
        //迭代
        Stream<Integer> iterate = Stream.iterate(0, (x) -> x + 2);
        iterate.limit(5)
                .forEach(System.out::println);


        //生成
        Stream<Integer> generate = Stream.generate(() -> (int) (Math.random() * 100));
        generate.limit(3)
                .forEach(System.out::println);
    }
}
